package simpledb.lock;

import simpledb.storage.PageId;
import simpledb.transaction.TransactionId;

public class PageLock {
    private final TransactionId tid;
    private final PageId pageId;
    private LockType type;

    private int count; // 重入计数

    public PageLock(TransactionId tid, PageId pageId, LockType type, int count) {
        this.tid = tid;
        this.pageId = pageId;
        this.type = type;
        this.count = count;
    }

    // 重入计数增减
    public void incrementCount() {
        this.count++;
    }

    public void decrementCount() {
        this.count--;
    }

    public TransactionId getTid() {
        return tid;
    }

    public PageId getPageId() {
        return pageId;
    }

    public LockType getType() {
        return type;
    }

    public void setType(LockType type) {
        this.type = type;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
